/**
 * 
 */
package com.orisper.esb.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.orisper.dao.Bm_productDao;
import com.orisper.dao.Bm_productPO;
import com.orisper.dao.Bm_product_faqDao;
import com.orisper.dao.Bm_product_faqPO;
import com.orisper.dao.Bm_product_imgDao;
import com.orisper.dao.Bm_product_imgPO;
import com.orisper.dao.Bm_product_paramsDao;
import com.orisper.dao.Bm_product_paramsPO;
import com.orisper.model.ApiMessage;
import com.orisper.utils.ApiConstants;
import com.orisper.utils.exception.ApiException;

import aos.framework.core.dao.SqlDao;
import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;

/**
 * @author Administrator
 *
 */
@Service
public class ApiProductService {

	@Autowired
	SqlDao sqlDao;
	
	@Autowired
	Bm_productDao bm_productDao;
	
	@Autowired
	Bm_product_faqDao bm_product_faqDao;
	
	@Autowired
	Bm_product_paramsDao bm_product_paramsDao;
	
	@Autowired
	Bm_product_imgDao bm_product_imgDao;
	
	/**
	 * 获取一级分类列表
	 * @param inDto
	 * @return
	 * @throws ApiException
	 */
	public ApiMessage getCatalogyList(Dto inDto) throws ApiException{
		ApiMessage msg=new ApiMessage();
		List<Dto> list = sqlDao.list("Api.getCatalogyList",null);
		msg.setCode(ApiConstants.REQ_SUCCESS);
		msg.setMessage(ApiConstants.MSG_SUCCESS);
		msg.setData(AOSJson.toJson(list));
		return msg;
	}
	
	
	/**
	 * 获取一级分类列表
	 * @param inDto
	 * @return
	 * @throws ApiException
	 */
	public ApiMessage getTypeList(Dto inDto) throws ApiException{
		ApiMessage msg=new ApiMessage();
		List<Dto> list = sqlDao.list("Api.getTypeList",inDto);
		msg.setCode(ApiConstants.REQ_SUCCESS);
		msg.setMessage(ApiConstants.MSG_SUCCESS);
		msg.setData(AOSJson.toJson(list));
		return msg;
	}
	
	
	
	
	/**
	 * 产品列表
	 * @param inDto
	 * @return
	 * @throws ApiException
	 */
	public ApiMessage getProductList(Dto inDto) throws ApiException{
		ApiMessage msg=new ApiMessage();
		//List<Dto> prodList = sqlDao.list("Api.getProductList",null);
		//List<Bm_productPO> list=bm_productDao.listPage(inDto);
		List<Dto> list=sqlDao.list("Api.getProductListPage", inDto);
        msg.setCode(ApiConstants.REQ_SUCCESS);
		msg.setMessage(ApiConstants.MSG_SUCCESS);
		msg.setData(AOSJson.toJson(list));
		return msg;
	}
	
	
	/**
	 * 产品详情
	 * @param inDto
	 * @return
	 * @throws ApiException
	 */
	public ApiMessage getProductDetail(Dto inDto) throws ApiException{
		ApiMessage msg=new ApiMessage();
		inDto.put("is_valid","1");
		Bm_productPO bm_productPO=bm_productDao.selectByKey(inDto.getString("id"));
		Dto qDto=Dtos.newDto();
		qDto.put("product_id", inDto.getString("id"));
		qDto.put("is_valid", "1");
		List<Bm_product_faqPO> faqList=bm_product_faqDao.list(qDto);
		List<Bm_product_paramsPO> paramsList=bm_product_paramsDao.list(qDto);
		List<Bm_product_imgPO> imgList=bm_product_imgDao.list(qDto);
		Dto outDto=Dtos.newDto();
		outDto.put("productPO", bm_productPO);
		outDto.put("faqList", faqList);
		outDto.put("paramList", paramsList);
		outDto.put("imgList", imgList);
		msg.setCode(ApiConstants.REQ_SUCCESS);
		msg.setMessage(ApiConstants.MSG_SUCCESS);
		msg.setData(AOSJson.toJson(outDto));
		return msg;
	}
	
}
